package com.mpyy.handler.purchase;

import com.alibaba.fastjson.JSON;
import com.mpyy.pojo.PurchaseStock;
import com.mpyy.pojo.PurchaseStockDesc;
import com.mpyy.pojo.SupplierInfo;
import com.mpyy.service.purchase.SupplierServiceInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author  oyh
 */
@Controller
public class SupplierController {

    @Autowired
    @Qualifier(value = "supplierServiceImpl")
    private SupplierServiceInter supplierServiceInter;

    @RequestMapping(value = {"/supplierController"})
    @ResponseBody
    public String supplierController(){
        List<SupplierInfo> supplierInfo = supplierServiceInter.saveSupplierInfo();
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("count",supplierInfo.size());
        map.put("data",supplierInfo);
        String maps = JSON.toJSONString(map);
        return maps;
    }

    @RequestMapping(value = {"/purchaseController"})
    @ResponseBody
    public String purchaseController(PurchaseStock purchaseStock){
        System.out.println("purchaseStock="+purchaseStock);
        List<PurchaseStock> purchaseStocks = supplierServiceInter.savePurchaseStock(purchaseStock);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("count",purchaseStocks.size());
        map.put("data",purchaseStocks);
        String maps = JSON.toJSONString(map);
        return maps;
    }

    @RequestMapping(value = {"/purchaseStockDescController"})
    @ResponseBody
    public String PurchaseStockDescController(PurchaseStockDesc purchaseStockDesc){
        System.out.println("purchaseStockDesc="+purchaseStockDesc);
        List<PurchaseStockDesc> purchaseStockDescs = supplierServiceInter.savePurchaseStockDesc(purchaseStockDesc);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("count",purchaseStockDescs.size());
        map.put("data",purchaseStockDescs);
        String maps = JSON.toJSONString(map);
        return maps;
    }
}